In this project, you are going to build an Real-Time Monitoring DHT11 with ESP32 and Node-RED using Myduino AIoT Education Kit. Your ESP32 will read temperature and humidity data from the DHT11 sensor, then automatically send the data to Node-RED Dashboard in real-time using MQTT protocol.
This exercise teaches you:
- How to use DHT11 with ESP32
- How to connect ESP32 with WiFi
- How to send sensor data using MQTT
- How to visualize IoT data with Node-RED Dashboard
Checklist Before Start
- How to use DHT11 with ESP32
- How to connect ESP32 with WiFi
- How to send sensor data using MQTT
- How to visualize IoT data with Node-RED Dashboard
NODE-RED Setup
Download Node_RED Desktop
Firstly before you start, you need to download the Node-RED Desktop first in your PC or laptop. Just click this link (https://vitormiao.com/Node-RED-Installer) and follow the step by step.
- Click “Download”

2. After settle download, open the file you downloaded just now. Click “More Info”.

3. Click “Run anyway”

4. Click “Next”

5. Click “Next”

6. Tick “Create a desktop shortcut”, click “Next”

7. Click “Install”

8. Click “Finish”

Setup Node-RED flow
After downloading Node-RED Desktop, you can set up the flow to connect Node-RED with the ESP32. Open Node-RED and follow these steps:

Step 1: Install Node-RED Dashboard nodes
- Go to the Menu at the top-right corner and click Manage Palette.

2. Click Install and search “node-red-dashboard“. Install the palette.

Step 2: Add MQTT-in nodes
- Drag two MQTT-in nodes into the flow.
- These will be used for the temperature and humidity topics.

Step 3: Configure node and add MQTT Broker
- Double-click one of the MQTT-in nodes.
- Click the “+” button to add a new MQTT broker.

Fill in the details (make sure the spelling are correct):
- Name: HiveMQ
- Server: broker.hivemq.com
- Click Add

3. Once added, the Server field will show the broker (HiveMQ).
4. Enter the topic: “esp32/your_name/temperature”
5. Click Done

As you can see, one of the mqtt in already turn into a temperature topic. You will only need to repeat the same process for another mqtt in humidity topic. Now, you need to setup another mqtt in as humidity topic.

Fill in the details (make sure the spelling is correct):
1. Server : (choose) HiveMQ
2. Topic : “esp32/your_name/humidity”
3. Done

Step 4 : Add Debug node
- Drag a Debug node into the flow
- Connect the Debug node to the temperature and humidity nodes

Step 5 : Add Dashboard Gauge Nodes and Setup Group
From the dashboard section in the left palette, drag chart node into your flow. Double click the first Gauge node:

- Click the “+” icon to add a new Dashboard group.

- Insert the Name as “ESP32 Project“
- Click “+”

- Just click the Add button right away

- Click Update

Now you just follow this setup:
- Group: Select or create a group (e.g., “ESP32 Project”).
- Label: Humidity (%)
- Units: %
- Range: Set Min = 0, Max = 100
- Click Done
Then connect the gauge node with humidity node.


Step 6 : Add Chart Node
Now you will add Chart node to the flow. Double click the chart node.

Follow this steps:
- Group : ESP32 Project
- Label : Temperature
- Y-axis : min = 0, max = 60
- Click Done
Connect the chart node with temperature node


Step 7 : Deploy and view Dashboard
- Click Deploy
- Click icon beside the setting
- Click Dashboard
- Click arrow icon beside Theme


Now we’re moving to circuit connections and Arduino IDE.
Circuit Connections

| Components | ESP32 Dev Module |
| DHT11 | IO4 |
| WS2812/RGB | IO16 |
Logic Flow
1. System Initialization
- ESP32 starts, initializes WiFi, MQTT client, DHT11, and WS2812 LEDs.
- All LEDs off at startup.
2. WiFi Connection
- ESP32 connects to WiFi (using SSID + password).
- If WiFi fails > retry until connected.
3. MQTT Connection
- ESP32 connects as MQTT client to broker (broker.hivemq.com).
- If broker unavailable, keep retrying until connected.
4. Sensor Reading (DHT11)
- Every 5 seconds:
- Read temperature (°C)
- Read humidity (%)
- If reading fails → skip this cycle.
5. Data Publishing (MQTT)
- Topic temperature > topic esp32/your_name/temperature
- Topic humidity > topic esp32/your_name/humidity
- Print readings to Serial Monitor for debugging.
6. Temperature LED Indicator (WS2812)
Based on the temperature value:
- Temperature < 25 °C
- All LEDs solid GREEN (safe range).
- Temperature between 26-28 °C
- All LEDs YELLOW blinking slowly (every 0.5s).
- Temperature ≥ 28 °C
- All LEDs RED blinking fast (every 0.2s).
7. Repeat Loop
- System loops back to Step 4.
- Continues reading > publishing > updating LEDs in real-time.
Code Lab
Step 1: Install Library
Before uploading your code into the ESP32, you need to install some library that you need for this project.
- Open the Library Manager at the sidebar
- Type the library name in the search bar
- If you don’t see at the top of the results, you might need to scroll down until you found it
- WiFi.h (already include in ESP32)
- PubSubClient.h (PubSubClient.h by Nick O’Leary)
- DHT.h (DHT sensor library by Adafruit)
- Adafruit_NeoPixel.h (Adafruit NeoPixel by Adafruit)

Step 2: Code
Copy and paste the code in Arduino IDE
// Flow system:
// 1. WiFi Connected > Appear ESP32 IP address
// 2. Connect to MQTT
// 3. Publish DHT11 data to Node-RED
// 4. RGB LED indicate
// i. temperature < 25 celcius = GREEN(solid)
// ii. temperature between 25 to 28 celcius = YELLOW(slow blinking)
// iii. temperature > 28 celcius = RED(fast blinking)
#include <WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
#include <Adafruit_NeoPixel.h>
// -------- WiFi Config --------
const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASSWORD";
const char* mqtt_server = "broker.hivemq.com"; // MQTT Broker IP
// -------- MQTT Topics --------
const char* tempTopic = "esp32/your_name/temperature";
const char* humTopic = "esp32/your_name/humidity";
// -------- DHT Config --------
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// -------- WS2812 Config --------
#define LED_PIN 5 // WS2812 DIN pin connected to GPIO5
#define NUM_LEDS 6
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
WiFiClient espClient;
PubSubClient client(espClient);
// -------- Global Variables --------
float currentTemp = 0;
unsigned long lastMsg = 0;
unsigned long lastBlink = 0;
bool ledState = false;
// -------- WiFi Setup --------
void setup_wifi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi connected");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
// -------- MQTT Reconnect --------
void reconnect() {
while (!client.connected()) {
Serial.print("Connecting to MQTT...");
if (client.connect("ESP32Client_your_name")) {
Serial.println(" Connected!");
} else {
Serial.print(" Failed, rc=");
Serial.print(client.state());
Serial.println(" retrying in 5s");
delay(5000);
}
}
}
// -------- LED Functions --------
void setAllLEDs(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(r, g, b));
}
strip.show();
}
// -------- Setup --------
void setup() {
Serial.begin(115200);
dht.begin();
strip.begin();
strip.show(); // Initialize all LEDs off
setup_wifi();
client.setServer(mqtt_server, 1883);
}
// -------- Main Loop --------
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
// ----- Publish sensor data every 5s -----
if (millis() - lastMsg > 5000) {
lastMsg = millis();
float t = dht.readTemperature();
float h = dht.readHumidity();
if (!isnan(t) && !isnan(h)) {
currentTemp = t; // store for LED control
char tempStr[8];
char humStr[8];
dtostrf(t, 1, 2, tempStr);
dtostrf(h, 1, 2, humStr);
client.publish(tempTopic, tempStr);
client.publish(humTopic, humStr);
Serial.printf("Published -> %s: %s °C | %s: %s %%\n", tempTopic, tempStr, humTopic, humStr);
} else {
Serial.println("Failed to read from DHT11");
}
}
// ----- LED control (runs continuously) -----
if (currentTemp < 26) {
// Solid Green
setAllLEDs(255, 0, 0);
}
else if (currentTemp >= 26 && currentTemp <= 28) {
// Yellow slow blinking every 0.5s
if (millis() - lastBlink > 500) {
lastBlink = millis();
ledState = !ledState;
if (ledState) setAllLEDs(255, 255, 0);
else setAllLEDs(0, 0, 0);
}
}
else if (currentTemp > 28) {
// Red fast blinking every 0.2s
if (millis() - lastBlink > 200) {
lastBlink = millis();
ledState = !ledState;
if (ledState) setAllLEDs(0, 255, 0);
else setAllLEDs(0, 0, 0);
}
}
}
There are lines you need to change before you upload
- Replace the SSID and PASSWORD with your own WiFi and password.

2. Replace the Topics with you own name (same as topic in the Node-RED).

3. Add your name in the client name

Step 3: Upload and Run
- Connect your ESP32 board
- Upload the code
- Open Serial Monitor at 115200 baud
- Look the data appear and publish to MQTT and Node-RED
System Check
Working properly if:
- Node-RED dashboard updates values every 5s.
- Serial Monitor shows “Published -> …”.
- Gauges reflect realistic temperature & humidity changes.



Troubleshooting Guide
| Problems | Solutions |
| No MQTT data | Check broker IP & firewall |
| Always 0 readings | Check DHT11 wiring |
| ESP32 upload error | Reconnect USB, select ESP32 Dev Module in Arduino IDE |
| WiFi not connecting | Double check WiFi SSID & Password |
| Node-RED no updates | Verify topics in Node-RED match ESP32 code |
Buy from:
Myduino AIoT Education Kit from Myduino.com






